/**
 * 题目：https://leetcode-cn.com/problems/perfect-squares/
 * 题解：https://shentuzhigang.blog.csdn.net/article/details/119463128
 */
class Solution {
    public int numSquares(int n) {
        int[] b = new int[10000];
        b[0] = 0;
        for (int i = 1; i <= n; i++) {
            b[i] = b[i - 1] + 1;
            for (int j = 2; j * j <= i; j++) {
                b[i] = Math.min(b[i], b[i - j * j] + 1);

            }
        }
        return b[n];
    }
}